name: "Prepare and publish test reports"
description: "Given go test results as plain text, prepare and publish test reports"

inputs:
  test-log-file:
    description: "Test log file to be used to generate reports"
    required: true
  test-step-conclusion:
    description: "Conclusion of the test step"
    required: true
  test-summary-suffix:
    description: "Suffix of the test summary file"
    required: true

runs:
  using: "composite"
  steps:
    - name: Install testjson2md
      shell: bash
      run: |
        cd tools/testjson2md
        go install
    - name: Prepare test report as json
      shell: bash
      run: |
        go tool test2json -t < ./${{ inputs.test-log-file }} > ./test-report.json
    - name: Publish test reports as markdown
      shell: bash
      env:
        PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
        PULL_REQUEST_AUTHOR: ${{ github.event.pull_request.user.login }}
        PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
      run: |
        testjson2md -in ./test-report.json \
          -out ./test-report.md \
          -out_summary ./test-report_${GITHUB_JOB}_${{ inputs.test-summary-suffix }}.json \
          -conclusion ${{ inputs.test-step-conclusion }}
        cat test-report.md >> $GITHUB_STEP_SUMMARY
    - name: Upload test reports summary as artifacts
      uses: actions/upload-artifact@v3
      with:
        name: test-reports
        path: ./test-report_*_*.json
